package de.blitzcoder.collide.gui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.Icon;

/**
 *
 * @author blitzcoder
 */
public class CloneCodeDocument extends CodeDocument implements Document.UpdateListener {

    private CodeDocument original;

    public CloneCodeDocument(CodeDocument original) {
        this.original = original;
        original.addUpdateListener(this);
    }

    public boolean close() {
        return true;
    }

    public Icon getIcon() {
        return original.getIcon();
    }

    public String getToolTip() {
        return original.getToolTip();
    }

    public void saveAs() {
        original.saveAs();
    }
    
    public void saveCode() {
        original.saveCode();
    }

    public File getFile() {
        return original.getFile();
    }

    public String getTitle() {
        return original.getTitle();
    }

    public boolean equalsFile(File f) {
        return original.equalsFile(f);
    }

    @Override
    protected void loadCode() throws IOException, FileNotFoundException, OutOfMemoryError {
        textArea.setBuffer(original.getTextArea().getBuffer());
    }

    @Override
    public boolean isClone() {
        return true;
    }

    @Override
    public Document cloneDocument() {
        return original.cloneDocument();
    }

    @Override
    public void update(Document doc) {
        fireDocumentUpdate();
    }

    @Override
    public Document getOriginal() {
        return original;
    }
}
